int h, s, lineStartX, lineStartY, lineEndX, lineEndY;
ArrayList<NormalLine> listOfLines;
boolean hasStartedToPress;

void setup() {
  smooth();

  //size(500,500); // To use in P5.

  background (0);

  stroke(255);
  strokeWeight(3);
  listOfLines = new ArrayList();

  lineStartX = -1;
  lineStartY = -1;
  lineEndX = -1;
  lineEndY = -1;
  hasStartedToPress = false;
}

void draw() {
  if ( hasStartedToPress ) {
    h = round(mouseY*255/height);
    s = round(mouseX*255/width); 
    background ( h, s, 100);
  }

  drawLines();

  if ( hasStartedToPress ) {
    line( lineStartX, lineStartY, mouseX, mouseY);
  }
}

void mousePressed() {
  if ( !hasStartedToPress ) {
    lineStartX = mouseX;
    lineStartY = mouseY;

    hasStartedToPress = true;
  }
}

void mouseReleased() {
  lineEndX = mouseX;
  lineEndY = mouseY;
  NormalLine tempLine = new NormalLine ( lineStartX, lineStartY, lineEndX, lineEndY );

  if ( hasStartedToPress ) {


    listOfLines.add( tempLine );

    hasStartedToPress = false;
  }
}

void drawLines() {
  int i;
  int linesArraySize = listOfLines.size();

  for (i=0; i<linesArraySize; i++) {
    listOfLines.get(i).draw();
  }
}
